
#ifndef LOGIC_H 
#define LOGIC_H 

#include "session.h"
#include "global.h"

#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <map>
#include <functional>
#include <mutex>
#include <thread>
#include <queue>

class Logic 
{
public:
    using FucCllBack = std::function<void(const std::shared_ptr<Session>&)>;

    Logic(const Logic& logic) = delete;
    Logic& operator=(const Logic& logic) = delete;
    ~Logic();

    void AddLogicNode(const std::shared_ptr<LogicNode>& node);
    static Logic& GetInstance();

private:
	Logic();

    //注册回调函数
    void _RegisterCallBacks();
    
    //MSG_HELLO_WORLD  1001  的回调函数
    void HelloWorldCallBack(const std::shared_ptr<Session>& session);

private:
    std::queue<std::shared_ptr<LogicNode>> m_logicNodes;
    std::mutex m_mutex;
    std::thread m_work_thread;
    std::condition_variable m_cond;
    std::map<uint32_t, FucCllBack> m_call_backs;
    bool m_is_stop;
};

#endif	/* LOGIC_H */
